package com.chen.mapper;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chen.entity.ExamChoose;
import com.chen.entity.ExamPaperConnectSubject;
import com.chen.vo.ESMDTO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 试卷与试题连接表Mapper
 */
public interface ExamPaperConnectSubjectMapper extends BaseMapper<ExamPaperConnectSubject> {

    /**
     * 根据考试编号获取试卷与题目关系信息
     * @param examPaperId
     * @return
     */
    default List<ExamPaperConnectSubject> findByExamPaperId(Integer examPaperId) {
        Wrapper<ExamPaperConnectSubject> queryWrapper = Wrappers.lambdaQuery(ExamPaperConnectSubject.class).eq(ExamPaperConnectSubject::getExamPaperId, examPaperId);
        return selectList(queryWrapper);
    }



    /**
     * 根据试卷id删除
     * @param examPaperId
     * @return
     */
    default Integer deleteByExamPaperId(Integer examPaperId) {
        Wrapper<ExamPaperConnectSubject> updateWrapper = Wrappers.lambdaUpdate(ExamPaperConnectSubject.class).eq(ExamPaperConnectSubject::getExamPaperId, examPaperId);
        return delete(updateWrapper);
    }

    /**
     * 根据试卷id和试题id查看
     * @param examPaperId
     * @param subjectId
     * @return
     */
    default ExamPaperConnectSubject findConnecByExamPaperIdAndSubjectId(Integer examPaperId, Integer subjectId) {
        Wrapper<ExamPaperConnectSubject> queryWrapper = Wrappers.lambdaQuery(ExamPaperConnectSubject.class).eq(ExamPaperConnectSubject::getExamPaperId, examPaperId).eq(ExamPaperConnectSubject::getSubjectId, subjectId);
        return selectOne(queryWrapper);
    }

    /**
     * 获取个数
     * @param examPaperId
     * @param subjectId
     * @return
     */
    default Long findCountByExamPaperIdAndSubjectId(Integer examPaperId, Integer subjectId) {
        Wrapper<ExamPaperConnectSubject> queryWrapper = Wrappers.lambdaQuery(ExamPaperConnectSubject.class).eq(ExamPaperConnectSubject::getExamPaperId, examPaperId).eq(ExamPaperConnectSubject::getSubjectId, subjectId);
        return selectCount(queryWrapper);
    }

    /**
     * 根据试卷id获取试卷题目详细信息
     * @param examPaperId
     * @return
     */
    public List<ESMDTO> getESM(@Param("examPaperId") Integer examPaperId, @Param("courseName") String courseName, @Param("courseId") Integer courseId, @Param("gradeId") Integer gradeId);

    /**
     * 按试卷id和试题id查询记录
     * @param examPaperId
     * @param subjectId
     * @return
     */
    default ExamPaperConnectSubject getSubjectByExamPaperIdAndSubjectId(Integer examPaperId, Integer subjectId) {
        Wrapper<ExamPaperConnectSubject> queryWrapper = Wrappers.lambdaQuery(ExamPaperConnectSubject.class).eq(ExamPaperConnectSubject::getExamPaperId, examPaperId).eq(ExamPaperConnectSubject::getSubjectId, subjectId);
        return selectOne(queryWrapper);
    }

    /**
     * 根据试题获取个数
     * @param subjectId
     * @return
     */
    default Long findCountBySubjectId(Integer subjectId) {
        Wrapper<ExamPaperConnectSubject> queryWrapper = Wrappers.lambdaQuery(ExamPaperConnectSubject.class).eq(ExamPaperConnectSubject::getSubjectId, subjectId);
        return selectCount(queryWrapper);
    }

}
